package Controleur;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import Modele.MonteCarloSimulationMulti;
import Vue.Fenetre;
import Vue.FenetreModifierMulti;

public class FenetreModifierControleurMulti implements Observer {
	
	private FenetreModifierMulti fm;
	private MonteCarloSimulationMulti model;
	private Fenetre fen;
	private Thread t;
	
	public FenetreModifierControleurMulti(FenetreModifierMulti fm,MonteCarloSimulationMulti model,Fenetre fen){
		this.fm=fm;
		this.model=model;
		this.fen=fen;
		model.addObserver(this);
		
		this.fm.modifierValeurListener(new classModifierVal());
		this.fm.cancelListener(new classCancel());
	}
	
	class classModifierVal implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			t=new Thread(new ThreadAction());
			t.start();			
		}
		
	}
	
	class classCancel implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			fm.dispose();
		}
		
	}

	@Override
	public void update(Observable o, Object arg) {
	}
	
	class ThreadAction implements Runnable{

		@Override
		public void run() {
			model.setRes(0.0);
			model.setSum(0.0);
			model.setS(Double.parseDouble(fm.getJtf1().getText()));
			model.setX(Double.parseDouble(fm.getJtf2().getText()));
			model.setR(Double.parseDouble(fm.getJtf3().getText()));
			model.setT(Double.parseDouble(fm.getJtf4().getText()));
			model.setB(Double.parseDouble(fm.getJtf5().getText()));
			model.setV(Double.parseDouble(fm.getJtf6().getText()));
			model.setnSteps(Integer.parseInt(fm.getJtf7().getText()));
			model.setnSimulations(Integer.parseInt(fm.getJtf8().getText()));
			fen.getBar().setMinimum(0);
			fen.getBar().setMaximum(Integer.parseInt(fm.getJtf8().getText()));
			fm.dispose();
			System.out.println(model.getS()+" "+model.getX()+" "+model.getR()+" "+model.getT()+" "+model.getB()+" "+model.getV()+" "+model.getnSteps()+" "+model.getnSimulations());
			long val=System.currentTimeMillis();
			model.calcule(fen.getCombo().getSelectedItem().toString());
			long val2=System.currentTimeMillis();
			long val3=val2-val;
			System.out.println("temps en ms : "+val3);
			
		}
		
	}

}
